# -*-coding:utf8 -*-
"""
根据jinja2 模版生成html模版
"""
from jinja2 import Environment, FileSystemLoader
from jinja2.environment import Template
import os
from datetime import date


class HanderGenHtml:
    def __init__(self) -> None:
        pass

    @staticmethod
    def gen_html_by_jinja2(temp_file=None, data_=None, outfile=None):
        """
        根据输入的jjinja2模版路径和输入的数据，以及要输出的html路径进行输出文件
        """
        env = Environment(loader=FileSystemLoader('./'))
        template = env.get_template(temp_file)
        with open(outfile, 'w+',encoding="utf-8") as fout:
            html_content = template.render(data=data_)
            fout.write(html_content)
        print("*"*10)
        print("生成Html页面成功")

    @staticmethod
    def get_img_path_from_outfile(dirs='./outfile'):
        """
        获取当前日期文件下的文件
        """
        today_ = date.today().strftime('%Y%m%d')
        index_0 = dirs+'/index0/'+today_+"/"
        index_0a = dirs+'/index0a/'+today_+"/"
        index_0b = dirs+'/index0b/'+today_+"/"

        data_ = {"index0": [], "index0a": [], "index0b": []}
        for root, dir, files in os.walk(index_0):
            for i in files:
                data_['index0'].append(os.path.join(root, i))

        for root, dir, files in os.walk(index_0a):
            for i in files:
                data_['index0a'].append(os.path.join(root, i))

        for root, dir, files in os.walk(index_0b):
            for i in files:
                data_['index0b'].append(os.path.join(root, i))

        #数据排序
        data_['index0'].sort(reverse=True)
        data_['index0a'].sort(reverse=True)
        data_['index0b'].sort(reverse=True)
        return data_
